package com.dongge.action;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

import java.lang.reflect.ParameterizedType;

/**
 * Created by Administrator on 2015/10/17.
 */
public abstract class BaseAction<T> extends ActionSupport implements ModelDriven<T> {

    protected T model = null;

    public BaseAction() {
        try{
            ParameterizedType parameterizedType = (ParameterizedType)this.getClass().getGenericSuperclass();
            Class<T> clazz = (Class<T>)parameterizedType.getActualTypeArguments()[0];
            model = clazz.newInstance();
        }
        catch (Exception e){
            throw new RuntimeException(e);
        }
    }

    public T getModel() {
        return model;
    }
}
